//引入第三方包
var express = require('express')

//实例化express
var app = express()


//设置静态资源托管文件
app.use(express.static('static'))

//在接口之前设置处理post请求中间件
app.use(express.json())
app.use(express.urlencoded({ extended: false }))


var arr = [
    { email: '178884773@qq.com', name: '张伟', phone: '13611129070', pass: '1234', ingroup: '编辑组', isadmin: true, status: true },
    { email: '178884773@qq.com', name: '李煜', phone: '13611129070', pass: '1234', ingroup: '编辑组', isadmin: true, status: true },
    { email: '178884773@qq.com', name: '李清照', phone: '13611129070', pass: '1234', ingroup: '编辑组', isadmin: true, status: false }
]
//设置接口
//req  请求对象，包含本次请求相关的信息
//res  响应请求，可以借助res向客户端返回信息
app.get('/user/list', (req, res) => {
    var { page,count } = req.body;
  

    //分页
    //slice 选取
    var newarr = arr.slice((page - 1) * count, page * count)
    //返回数据


    res.send({ code: 200, msg: '请求成功', list: newarr })
})

//搜索
// app.get('/user/search',())

app.post('/user/login', (req, res) => {

    var { phone, pass } = req.body;
    console.log('收到了来自客户端的请求');

    res.send({ code: 200, msg: '登陆成功' })
})

//设置监听
app.listen(8888, () => {
    console.log('服务器端运行在:http://localhost:8888');
})